home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / wiredsprites / application files / wiredspriteutilities.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  42.9 KB  |  1,279 lines

  1. //////////
  2. //
  3. //    File:        WiredSpriteUtilities.c
  4. //
  5. //    Contains:    Utilities for creating wired sprite media.
  6. //
  7. //    Written by:    Sean Allen
  8. //    Revised by:    Chris Flick and Tim Monroe
  9. //
  10. //    Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <3>         03/29/98    rtm        added Endian macros to flags parameter in AddActionParameterOptions
  15. //       <2>         03/??/98    cf        added Endian macros
  16. //       <1>         12/??/97    sa        first file
  17. //
  18. //    NOTES:
  19. //
  20. //    ***(1)***
  21. //    You need to pay attention to the endian-ness of the data you pass to these routines. Wired sprite
  22. //    media data is stored in QuickTime atoms and atom containers and must therefore be big-endian. We've
  23. //    tried to conform to this rule: if the data to be written to a wired sprite media is 4 bytes or less,
  24. //    then we will perform the endian swap for you. There are several exceptions to this rule; for instance,
  25. //    we swap the data in any matrices you pass to the AddSpriteSetMatrixAction function. But we do not swap
  26. //    the data in any matrices passed to AddActionParameterOptions (since we don't know that they are matrices!).
  27. //    Let the caller beware!
  28. //
  29. //////////
  30.  
  31. #ifndef _WIREDSPRITEUTILITIES_
  32. #include "WiredSpriteUtilities.h"
  33. #endif
  34.  
  35. #ifndef __ENDIANUTILITIES__
  36. #include "EndianUtilities.h"
  37. #endif
  38.  
  39. /*
  40.  
  41. These atoms are at same level as sprite property atoms
  42.  
  43. [(SpriteActionAtoms)] = 
  44.     kQTEventType, theQTEventType, (1 .. numEventTypes)
  45.             [(ActionListAtoms)]
  46.  
  47. This atom is at same level as kSpriteAtomType atoms
  48.  
  49. <kQTEventFrameLoaded>, 1, 1
  50.     [(ActionListAtoms)]
  51.         
  52. [(ActionListAtoms)] = 
  53.     kAction, (anyUniqueIDs), (1..numActions)
  54.         kWhichAction    1, 1
  55.             [long whichActionConstant]
  56.         <kActionParameter>    (anyUniqueIDs), (1..numParameters)
  57.             [parameter data depending on actionConstant and paramIndex]
  58.         <kActionFlags>    parameterID,  (1..numParamsWithFlags)
  59.             [long actionFlags]
  60.         <kActionParameterMinValue>    parameterID,  (1.. numParamsWithMin)
  61.             [data depends on param type]
  62.         <kActionParameterMaxValue>    parameterID,  (1.. numParamsWithMax)
  63.             [data depends on param type]
  64.         [(ActionTargetAtoms)]
  65.  
  66. [(ActionTargetAtoms)] =
  67.     <kActionTarget>
  68.         <kTargetMovie>
  69.             [no data]
  70.         <kTargetTrackName>
  71.             [PString trackName]
  72.         <kTargetTrackType>
  73.             [OSType trackType]
  74.         <kTargetTrackIndex>
  75.             [long trackIndex]
  76.             OR
  77.             [(kExpressionAtoms)]
  78.         <kTargetTrackID>
  79.             [long trackID]
  80.             OR
  81.             [(kExpressionAtoms)]
  82.         <kTargetSpriteName>
  83.             [PString spriteName]
  84.         <kTargetSpriteIndex>
  85.             [short spriteIndex]
  86.             OR
  87.             [(kExpressionAtoms)]
  88.         <kTargetSpriteID>
  89.             [QTAtomID spriteIID]
  90.             OR
  91.             [(kExpressionAtoms)]
  92.  
  93.  
  94. Both [(CaseStatementActionAtoms)] and [(WhileStatementActionAtoms)]
  95. are child atoms of a kActionParameter 1, 1 atom
  96.  
  97. [(CaseStatementActionAtoms)] =
  98.     kConditionalAtomType, (anyUniqueIDs), (1..numCases)
  99.         [(kExpressionAtoms)]
  100.         kActionListAtomType 1, 1
  101.             [(ActionListAtoms)]            // may contain nested conditional actions
  102.     
  103. [(WhileStatementActionAtoms)] =
  104.     kConditionalAtomType, 1, 1
  105.         [(kExpressionAtoms)]
  106.         kActionListAtomType 1, 1
  107.             [(ActionListAtoms)]                // may contain nested conditional actions
  108.  
  109. [(kExpressionAtoms)] =
  110.     kExpressionContainerAtomType, 1, 1
  111.         <kOperatorAtomType, theOperatorType, 1>
  112.             kOperandAtomType, (anyUniqueIDs), (1..numOperands)
  113.                 [(OperandAtoms)]
  114.         OR
  115.         <kOperandAtomType, 1, 1>
  116.             [(OperandAtoms)]
  117.  
  118. [(OperandAtoms)] = 
  119.     <kExpressionOperandAtomType> 1, 1
  120.         [(kExpressionAtoms)]                    // allows for recursion
  121.     OR
  122.     <kConstantOperandAtomType> 1, 1
  123.         [ float theConstant ]
  124.     OR
  125.     <kSpriteVariableOperandAtomType> 1, 1
  126.         [(ActionTargetAtoms)]
  127.         kActionParameter, 1, 1
  128.             [QTAtomID spriteVariableID]
  129.     OR
  130.     <kOperandKeyIsDown> 1, 1
  131.         [(ActionTargetAtoms)]
  132.         kActionParameter, 1, 1
  133.             [UInt16 modifierKeys]
  134.         kActionParameter, 2, 2
  135.             [UInt8 asciiCharCode]
  136.     OR        
  137.     <any other operand atom type>
  138.         [(ActionTargetAtoms)]
  139. */
  140.  
  141. // exception handling macros
  142.  
  143. #define        FailIf(a, e)         {if (a)     { err = e; goto bail; }}
  144. #define        FailOSErr(a)         {if (err = a)     goto bail;}
  145. #define        FailMemErr(a)        {a; if (err = MemError()) goto bail;}
  146.  
  147. // for the kQTEventFrameLoaded event, the actionAtoms atom should be a sibling of a kSpriteAtomType
  148.  
  149. OSErr AddQTEventAtom( QTAtomContainer container, QTAtom actionAtoms, QTAtomID theQTEventType, QTAtom *newQTEventAtom )
  150. {
  151.     OSErr    err = noErr;
  152.     
  153.     if ( (! container) || (theQTEventType == 0) || (newQTEventAtom == nil) )    { err = paramErr; goto bail; }
  154.     
  155.     if ( theQTEventType == kQTEventFrameLoaded ) {
  156.         FailOSErr( QTInsertChild( container, actionAtoms, kQTEventFrameLoaded, 1, 1, 0, nil, newQTEventAtom ) );
  157.     }
  158.     else {
  159.         *newQTEventAtom =  QTFindChildByID( container, actionAtoms, kQTEventType, theQTEventType, nil );
  160.         if ( ! *newQTEventAtom ) {
  161.             FailOSErr( QTInsertChild( container, actionAtoms, kQTEventType, theQTEventType, 1, 0, nil, newQTEventAtom ) );
  162.         }
  163.     }
  164.     
  165. bail:
  166.     return err;
  167. }
  168.  
  169. OSErr AddActionAtom( QTAtomContainer container, QTAtom eventAtom, long whichActionConstant, QTAtom *newActionAtom )
  170. {
  171.     OSErr    err = noErr;
  172.     QTAtom    actionAtom;
  173.     
  174.     if ( (! container) || (whichActionConstant == 0) )    { return paramErr; }
  175.     
  176.     FailOSErr( QTInsertChild( container, eventAtom, kAction, 0, 0, 0, nil, &actionAtom ) );
  177.  
  178.     whichActionConstant = EndianU32_NtoB(whichActionConstant);
  179.     FailOSErr( QTInsertChild( container, actionAtom, kWhichAction, 1, 1, sizeof(whichActionConstant), &whichActionConstant, nil ) );
  180.     
  181. bail:
  182.     if ( newActionAtom ) {
  183.         if ( err )    
  184.             *newActionAtom = 0;
  185.         else
  186.             *newActionAtom = actionAtom;
  187.     }
  188.     return err;
  189. }
  190.  
  191. OSErr AddActionParameterAtom( QTAtomContainer container, QTAtom actionAtom, long parameterIndex, long paramDataSize, void *paramData, QTAtom *newParamAtom )
  192. {
  193.     return QTInsertChild( container, actionAtom, kActionParameter, 0, (short)parameterIndex, paramDataSize, paramData, newParamAtom );
  194. }
  195.  
  196. OSErr AddActionParameterOptions( QTAtomContainer container, QTAtom actionAtom, QTAtomID paramID, long flags, long minValueSize,
  197.                             void *minValue, long maxValueSize, void *maxValue )
  198. {
  199.     OSErr    err = noErr;
  200.  
  201.     flags = EndianU32_NtoB(flags);
  202.     FailOSErr( QTInsertChild( container, actionAtom, kActionFlags, paramID, 0, sizeof(flags), &flags, nil ) );
  203.     if ( minValue ) {
  204.         FailOSErr( QTInsertChild( container, actionAtom, kActionParameterMinValue, paramID, 0, minValueSize, minValue, nil ) );
  205.     }
  206.     if ( maxValue ) {
  207.         FailOSErr( QTInsertChild( container, actionAtom, kActionParameterMaxValue, paramID, 0, maxValueSize, maxValue, nil ) );
  208.     }
  209.  
  210. bail:
  211.     return err;
  212. }
  213.  
  214. OSErr AddTrackNameActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, Str255 trackName, QTAtom *newTargetAtom )
  215. {
  216.     OSErr    err = noErr;
  217.     QTAtom    targetAtom;
  218.     
  219.     if ( newTargetAtom )    *newTargetAtom = 0;
  220.     
  221.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  222.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  223.     FailOSErr( QTInsertChild( container, targetAtom, kTargetTrackName, 1, 1, trackName[0] + 1, trackName, nil ) );
  224.  
  225. bail:
  226.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  227.     return err;
  228. }
  229.  
  230. OSErr AddTrackIDActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, long trackID, QTAtom *newTargetAtom )
  231. {
  232.     OSErr    err = noErr;
  233.     QTAtom    targetAtom;
  234.     
  235.     if ( newTargetAtom )    *newTargetAtom = 0;
  236.     
  237.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  238.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  239.         
  240.     trackID = EndianU32_NtoB(trackID);
  241.     FailOSErr( QTInsertChild( container, targetAtom, kTargetTrackID, 1, 1, sizeof(trackID), &trackID, nil ) );
  242.  
  243. bail:
  244.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  245.     return err;
  246. }
  247.  
  248. OSErr AddTrackTypeActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, OSType trackType, QTAtom *newTargetAtom )
  249. {
  250.     OSErr    err = noErr;
  251.     QTAtom    targetAtom;
  252.     
  253.     if ( newTargetAtom )    *newTargetAtom = 0;
  254.     
  255.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  256.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  257.         
  258.     trackType = EndianU32_NtoB(trackType);
  259.     FailOSErr( QTInsertChild( container, targetAtom, kTargetTrackType, 1, 1, sizeof(trackType), &trackType, nil ) );
  260.  
  261. bail:
  262.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  263.     return err;
  264. }
  265.  
  266. OSErr AddTrackIndexActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, long trackIndex, QTAtom *newTargetAtom )
  267. {
  268.     OSErr    err = noErr;
  269.     QTAtom    targetAtom;
  270.     
  271.     if ( newTargetAtom )    *newTargetAtom = 0;
  272.     
  273.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  274.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  275.  
  276.     trackIndex = EndianU32_NtoB(trackIndex);
  277.     FailOSErr( QTInsertChild( container, targetAtom, kTargetTrackIndex, 1, 1, sizeof(trackIndex), &trackIndex, nil ) );
  278.  
  279. bail:
  280.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  281.     return err;
  282. }
  283.  
  284. OSErr AddSpriteNameActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, Str255 spriteName, QTAtom *newTargetAtom )
  285. {
  286.     OSErr    err = noErr;
  287.     QTAtom    targetAtom;
  288.     
  289.     if ( newTargetAtom )    *newTargetAtom = 0;
  290.     
  291.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  292.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  293.     FailOSErr( QTInsertChild( container, targetAtom, kTargetSpriteName, 1, 1, spriteName[0] + 1, spriteName, nil ) );
  294.  
  295. bail:
  296.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  297.     return err;
  298. }
  299.  
  300. OSErr AddSpriteIDActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, QTAtomID spriteID, QTAtom *newTargetAtom )
  301. {
  302.     OSErr    err = noErr;
  303.     QTAtom    targetAtom;
  304.     
  305.     if ( newTargetAtom )    *newTargetAtom = 0;
  306.     
  307.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  308.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  309.  
  310.     spriteID = EndianU32_NtoB(spriteID);
  311.     FailOSErr( QTInsertChild( container, targetAtom, kTargetSpriteID, 1, 1, sizeof(spriteID), &spriteID, nil ) );
  312.  
  313. bail:
  314.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  315.     return err;
  316. }
  317.  
  318. OSErr AddSpriteIndexActionTargetAtom( QTAtomContainer container, QTAtom actionAtom, short spriteIndex, QTAtom *newTargetAtom )
  319. {
  320.     OSErr    err = noErr;
  321.     QTAtom    targetAtom;
  322.     
  323.     if ( newTargetAtom )    *newTargetAtom = 0;
  324.     
  325.     if ( ! (targetAtom = QTFindChildByIndex( container, actionAtom, kActionTarget, 1, nil )) )
  326.         FailOSErr( QTInsertChild( container, actionAtom, kActionTarget, 1, 1, 0, nil, &targetAtom ) );
  327.  
  328.     spriteIndex = EndianU16_NtoB(spriteIndex);
  329.     FailOSErr( QTInsertChild( container, targetAtom, kTargetSpriteIndex, 1, 1, sizeof(spriteIndex), &spriteIndex, nil ) );
  330.  
  331. bail:
  332.     if ( newTargetAtom )    *newTargetAtom = targetAtom;
  333.     return err;
  334. }
  335.  
  336.  
  337. //______ High level WiredSprite Utilities _____
  338.  
  339.  
  340. OSErr AddQTEventAndActionAtoms( QTAtomContainer container, QTAtom atom, long whichEvent, long whichAction, QTAtom *actionAtom )
  341. {
  342.     OSErr    err = noErr;
  343.     QTAtom    eventAtom;
  344.     
  345.     eventAtom = atom;
  346.     
  347.     if ( whichEvent != 0 )
  348.         FailOSErr( AddQTEventAtom( container, atom, whichEvent, &eventAtom ) );
  349.     
  350.     FailOSErr( AddActionAtom( container, eventAtom, whichAction, actionAtom ) );
  351.  
  352. bail:
  353.     return err;
  354. }
  355.  
  356. // trackTypeIndex only used if trackTargetType is kTargetTrackType, can be zero for default index of 1
  357. OSErr AddTrackTargetAtom( QTAtomContainer container, QTAtom actionAtom, long trackTargetType, void *trackTarget, long trackTypeIndex )
  358. {
  359.     OSErr    err = noErr;
  360.     
  361.     // allow zero for default target, the sprite track which received the event
  362.     if ( trackTargetType ) {
  363.         switch ( trackTargetType ) {
  364.             case kTargetTrackName: {
  365.                     StringPtr trackName = trackTarget;
  366.                     FailOSErr( AddTrackNameActionTargetAtom( container, actionAtom, trackName, nil ) );
  367.                 }
  368.                 break;
  369.                 
  370.             case kTargetTrackID: {
  371.                     long trackID = (long)trackTarget;
  372.                     FailOSErr( AddTrackIDActionTargetAtom( container, actionAtom, trackID, nil ) );
  373.                 }
  374.                 break;
  375.  
  376.             case kTargetTrackType: {
  377.                     OSType trackType = (long)trackTarget;
  378.                     FailOSErr( AddTrackTypeActionTargetAtom( container, actionAtom, trackType, nil ) );
  379.                     if ( trackTypeIndex )
  380.                         FailOSErr( AddTrackIndexActionTargetAtom( container, actionAtom, trackTypeIndex, nil ) );
  381.                 }
  382.                 break;
  383.                         
  384.             case kTargetTrackIndex: {
  385.                     long trackIndex = (long)trackTarget;
  386.                     FailOSErr( AddTrackIndexActionTargetAtom( container, actionAtom, trackIndex, nil ) );
  387.                 }
  388.                 break;
  389.                         
  390.             default:
  391.                 err = paramErr; 
  392.         }
  393.     }
  394.     
  395. bail:
  396.     return err;
  397. }
  398.  
  399. OSErr AddSpriteTargetAtom( QTAtomContainer container, QTAtom actionAtom, long spriteTargetType, void *spriteTarget )
  400. {
  401.     OSErr    err = noErr;
  402.     
  403.     // allow zero for default target, the sprite which received the event
  404.     if ( spriteTargetType ) {
  405.         switch ( spriteTargetType ) {
  406.             case kTargetSpriteName: {
  407.                     StringPtr spriteName = spriteTarget;
  408.                     FailOSErr( AddSpriteNameActionTargetAtom( container, actionAtom, spriteName, nil ) );
  409.                 }
  410.                 break;
  411.                 
  412.             case kTargetSpriteID: {
  413.                     QTAtomID spriteID = (QTAtomID)spriteTarget;
  414.                     FailOSErr( AddSpriteIDActionTargetAtom( container, actionAtom, spriteID, nil ) );
  415.                 }
  416.                 break;
  417.  
  418.             case kTargetSpriteIndex: {
  419.                     short spriteIndex = (short)spriteTarget;
  420.                     FailOSErr( AddSpriteIndexActionTargetAtom( container, actionAtom, spriteIndex, nil ) );
  421.                 }
  422.                 break;
  423.                         
  424.             default:
  425.                 err = paramErr; 
  426.         }
  427.     }
  428. bail:
  429.     return err;
  430. }
  431.  
  432. OSErr AddTrackAndSpriteTargetAtoms( QTAtomContainer container, QTAtom actionAtom, long trackTargetType, void *trackTarget, long trackTypeIndex, 
  433.                                     long spriteTargetType, void *spriteTarget )
  434. {
  435.     OSErr    err = noErr;
  436.     
  437.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  438.     
  439.     FailOSErr( AddSpriteTargetAtom( container, actionAtom, spriteTargetType, spriteTarget ) );
  440.     
  441. bail:
  442.     return err;
  443. }
  444.  
  445. OSErr AddMovieSetVolumeAction( QTAtomContainer container, QTAtom atom, long whichEvent, short volume )
  446. {    
  447.     OSErr    err = noErr;
  448.     QTAtom    actionAtom;
  449.     
  450.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetVolume, &actionAtom ) );
  451.  
  452.     volume = EndianS16_NtoB(volume);
  453.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(volume), &volume, nil ) );
  454.  
  455.     // the movie is the default target for movie actions
  456.     
  457. bail:
  458.     return err;
  459. }
  460.  
  461. OSErr AddMovieSetRateAction( QTAtomContainer container, QTAtom atom, long whichEvent, Fixed rate )
  462. {    
  463.     OSErr    err = noErr;
  464.     QTAtom    actionAtom;
  465.     
  466.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetRate, &actionAtom ) );
  467.  
  468.     rate = EndianS32_NtoB(rate);
  469.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(rate), &rate, nil ) );
  470.  
  471.     // the movie is the default target for movie actions
  472.     
  473. bail:
  474.     return err;
  475. }
  476.  
  477. OSErr AddMovieSetLoopingFlagsAction( QTAtomContainer container, QTAtom atom, long whichEvent, long loopingFlags )
  478. {    
  479.     OSErr    err = noErr;
  480.     QTAtom    actionAtom;
  481.     
  482.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetLoopingFlags, &actionAtom ) );
  483.  
  484.     loopingFlags = EndianU32_NtoB(loopingFlags);
  485.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(loopingFlags), &loopingFlags, nil ) );
  486.  
  487.     // the movie is the default target for movie actions
  488.     
  489. bail:
  490.     return err;
  491. }
  492.  
  493. OSErr AddMovieGoToTimeAction( QTAtomContainer container, QTAtom atom, long whichEvent, TimeValue time )
  494. {    
  495.     OSErr    err = noErr;
  496.     QTAtom    actionAtom;
  497.     
  498.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieGoToTime, &actionAtom ) );
  499.  
  500.     time = EndianS32_NtoB(time);
  501.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(time), &time, nil ) );
  502.  
  503.     // the movie is the default target for movie actions
  504.     
  505. bail:
  506.     return err;
  507. }
  508.  
  509. OSErr AddMovieGoToTimeByNameAction( QTAtomContainer container, QTAtom atom, long whichEvent, Str255 timeName )
  510. {    
  511.     OSErr    err = noErr;
  512.     QTAtom    actionAtom;
  513.     
  514.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieGoToTimeByName, &actionAtom ) );
  515.  
  516.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, timeName[0] + 1, timeName, nil ) );
  517.  
  518.     // the movie is the default target for movie actions
  519.     
  520. bail:
  521.     return err;
  522. }
  523.  
  524. OSErr AddMovieGoToBeginningAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  525. {    
  526.     OSErr    err = noErr;
  527.     QTAtom    actionAtom;
  528.     
  529.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieGoToBeginning, &actionAtom ) );
  530.  
  531.     // the movie is the default target for movie actions
  532.     
  533. bail:
  534.     return err;
  535. }
  536.  
  537. OSErr AddMovieGoToEndAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  538. {    
  539.     OSErr    err = noErr;
  540.     QTAtom    actionAtom;
  541.     
  542.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieGoToEnd, &actionAtom ) );
  543.  
  544.     // the movie is the default target for movie actions
  545.     
  546. bail:
  547.     return err;
  548. }
  549.  
  550. OSErr AddMovieStepForwardAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  551. {    
  552.     OSErr    err = noErr;
  553.     QTAtom    actionAtom;
  554.     
  555.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieStepForward, &actionAtom ) );
  556.  
  557.     // the movie is the default target for movie actions
  558.     
  559. bail:
  560.     return err;
  561. }
  562.  
  563. OSErr AddMovieStepBackwardAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  564. {    
  565.     OSErr    err = noErr;
  566.     QTAtom    actionAtom;
  567.     
  568.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieStepBackward, &actionAtom ) );
  569.  
  570.     // the movie is the default target for movie actions
  571.     
  572. bail:
  573.     return err;
  574. }
  575.  
  576. OSErr AddMovieSetSelectionAction( QTAtomContainer container, QTAtom atom, long whichEvent, TimeValue startTime, TimeValue endTime )
  577. {    
  578.     OSErr    err = noErr;
  579.     QTAtom    actionAtom;
  580.     
  581.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetSelection, &actionAtom ) );
  582.  
  583.     startTime = EndianS32_NtoB(startTime);
  584.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(startTime), &startTime, nil ) );
  585.  
  586.     endTime = EndianS32_NtoB(endTime);
  587.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, sizeof(endTime), &endTime, nil ) );
  588.  
  589.     // the movie is the default target for movie actions
  590.     
  591. bail:
  592.     return err;
  593. }
  594.  
  595. OSErr AddMovieSetSelectionByNameAction( QTAtomContainer container, QTAtom atom, long whichEvent, Str255 startTimeName, Str255 endTimeName )
  596. {    
  597.     OSErr    err = noErr;
  598.     QTAtom    actionAtom;
  599.     
  600.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetSelectionByName, &actionAtom ) );
  601.  
  602.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, startTimeName[0] + 1, startTimeName, nil ) );
  603.  
  604.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, endTimeName[0] + 1, endTimeName, nil ) );
  605.  
  606.     // the movie is the default target for movie actions
  607.     
  608. bail:
  609.     return err;
  610. }
  611.  
  612. OSErr AddMoviePlaySelectionAction( QTAtomContainer container, QTAtom atom, long whichEvent, Boolean selectionOnly )
  613. {
  614.     OSErr    err = noErr;
  615.     QTAtom    actionAtom;
  616.     
  617.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMoviePlaySelection, &actionAtom ) );
  618.  
  619.     // Booleans don't need endian flipping
  620.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(selectionOnly), &selectionOnly, nil ) );
  621.  
  622.     // the movie is the default target for movie actions
  623.     
  624. bail:
  625.     return err;
  626. }
  627.  
  628. OSErr AddMovieSetLanguage( QTAtomContainer container, QTAtom atom, long whichEvent, long language )
  629. {
  630.     OSErr    err = noErr;
  631.     QTAtom    actionAtom;
  632.     
  633.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMovieSetLanguage, &actionAtom ) );
  634.  
  635.     language = EndianS32_NtoB(language);
  636.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(language), &language, nil ) );
  637.  
  638.     // the movie is the default target for movie actions
  639.     
  640. bail:
  641.     return err;
  642. }
  643.  
  644. OSErr AddTrackSetVolumeAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  645.                                void *trackTarget, long trackTypeIndex, short volume )
  646. {
  647.     OSErr    err = noErr;
  648.     QTAtom    actionAtom;
  649.     
  650.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetVolume, &actionAtom ) );
  651.  
  652.     volume = EndianS16_NtoB(volume);
  653.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(volume), &volume, nil ) );
  654.  
  655.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  656.     
  657. bail:
  658.     return err;
  659. }
  660.  
  661. OSErr AddTrackSetBalanceAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  662.                                 void *trackTarget, long trackTypeIndex, short balance )
  663. {
  664.     OSErr    err = noErr;
  665.     QTAtom    actionAtom;
  666.     
  667.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetBalance, &actionAtom ) );
  668.  
  669.     balance = EndianS16_NtoB(balance);
  670.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(balance), &balance, nil ) );
  671.  
  672.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  673.     
  674. bail:
  675.     return err;
  676. }
  677.  
  678. OSErr AddTrackSetEnabledAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  679.                                 void *trackTarget, long trackTypeIndex, Boolean enabled )
  680. {
  681.     OSErr    err = noErr;
  682.     QTAtom    actionAtom;
  683.     
  684.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetEnabled, &actionAtom ) );
  685.  
  686.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(enabled), &enabled, nil ) );
  687.  
  688.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  689.     
  690. bail:
  691.     return err;
  692. }
  693.  
  694. OSErr AddTrackSetMatrixAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  695.                                void *trackTarget, long trackTypeIndex, MatrixRecordPtr matrix, QTAtom *actionAtom )
  696. {
  697.     OSErr            err = noErr;
  698.     QTAtom            theActionAtom = 0;
  699.     MatrixRecord    bigEndianMatrix;
  700.     
  701.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetMatrix, &theActionAtom ) );
  702.  
  703.     bigEndianMatrix = *matrix;
  704.     EndianUtils_MatrixRecord_NtoB( &bigEndianMatrix );
  705.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(MatrixRecord), &bigEndianMatrix, nil ) );
  706.  
  707.     FailOSErr( AddTrackTargetAtom( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  708.     
  709.     if ( actionAtom )
  710.         *actionAtom = theActionAtom;
  711. bail:
  712.     return err;
  713. }
  714.  
  715. OSErr AddTrackSetLayerAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  716.                               void *trackTarget, long trackTypeIndex, short layer )
  717. {
  718.     OSErr    err = noErr;
  719.     QTAtom    actionAtom;
  720.     
  721.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetLayer, &actionAtom ) );
  722.  
  723.     layer = EndianS16_NtoB(layer);
  724.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(layer), &layer, nil ) );
  725.  
  726.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  727.     
  728. bail:
  729.     return err;
  730. }
  731.  
  732. OSErr AddTrackSetClipAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  733.                              void *trackTarget, long trackTypeIndex, RgnHandle clip )
  734. {
  735.     OSErr            err = noErr;
  736.     QTAtom            actionAtom;
  737. #if TARGET_RT_LITTLE_ENDIAN
  738.     RgnHandle        bigEndianClip = nil;
  739. #else
  740.     SignedByte        saveState;
  741. #endif
  742.     
  743.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionTrackSetClip, &actionAtom ) );
  744.  
  745.     // clip is native-endian but it needs to be big endian to be stored in the data atom container.
  746.     // We need a routine to flip it.
  747.  
  748. #if TARGET_RT_LITTLE_ENDIAN
  749.     // For little endian platforms, we copy the clip into a temporary region handle and then flip that region
  750.     bigEndianClip = (RgnHandle)NewHandle(0);
  751.     if( err = MemError() ) goto bail;
  752.     
  753.     err = HandAndHand( (Handle)clip, (Handle)bigEndianClip );
  754.     if( err ) goto bail;
  755.     
  756.     EndianUtils_RgnHandle_NtoB( bigEndianClip );
  757.  
  758.     HLockHi((Handle) bigEndianClip );    // Lock the handle down so that it doesn't move during addition to container QTAtomContainer. We
  759.                                         // don't unlock since we dispose of it at bottom of this function.
  760.  
  761.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, GetHandleSize((Handle)bigEndianClip), *bigEndianClip, nil ) );
  762. #else
  763.     // For big endian platforms, just add the clip
  764.     
  765.     // Lock the handle down so that it doesn't move during addition to container QTAtomContainer. Save state so that we
  766.     // can restore its "lockedness" when we're done.
  767.     saveState = HGetState((Handle) clip );
  768.     HLockHi((Handle) clip );
  769.     
  770.         FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, GetHandleSize((Handle)clip), (void *)clip, nil ) );
  771.     
  772.     HSetState((Handle) clip, saveState );    // Restore handle's "lockedness"
  773. #endif
  774.  
  775.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  776.     
  777. bail:
  778.  
  779. #if TARGET_RT_LITTLE_ENDIAN
  780.     if( bigEndianClip )    DisposeRgn( bigEndianClip );
  781. #endif
  782.     
  783.     return err;
  784. }
  785.  
  786. OSErr AddSpriteSetMatrixAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType,
  787.                                 void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  788.                                 MatrixRecordPtr matrix, QTAtom *actionAtom )
  789. {
  790.     OSErr            err = noErr;
  791.     QTAtom            theActionAtom;
  792.     MatrixRecord    bigEndianMatrix;
  793.     
  794.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteSetMatrix, &theActionAtom ) );
  795.  
  796.     bigEndianMatrix = *matrix;
  797.     EndianUtils_MatrixRecord_NtoB( &bigEndianMatrix );
  798.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(MatrixRecord), &bigEndianMatrix, nil ) );
  799.  
  800.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  801.                                              spriteTargetType, spriteTarget ) );
  802.     if ( actionAtom )
  803.         *actionAtom = theActionAtom;
  804.                                                 
  805. bail:
  806.     return err;
  807. }
  808.  
  809. OSErr AddSpriteSetImageIndexAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType,
  810.                                     void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  811.                                     short setImageIndex, QTAtom *actionAtom )
  812. {
  813.     OSErr    err = noErr;
  814.     QTAtom    theActionAtom;
  815.     
  816.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteSetImageIndex, &theActionAtom ) );
  817.  
  818.     setImageIndex = EndianS16_NtoB(setImageIndex);
  819.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(setImageIndex), &setImageIndex, nil ) );
  820.  
  821.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  822.                                              spriteTargetType, spriteTarget ) );
  823.     if ( actionAtom )
  824.         *actionAtom = theActionAtom;
  825.                                                 
  826. bail:
  827.     return err;
  828. }
  829.  
  830. OSErr AddSpriteSetVisibleAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  831.                                  void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  832.                                  short visible, QTAtom *actionAtom )
  833. {
  834.     OSErr    err = noErr;
  835.     QTAtom    theActionAtom;
  836.     
  837.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteSetVisible, &theActionAtom ) );
  838.  
  839.     visible = EndianS16_NtoB(visible);
  840.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(visible), &visible, nil ) );
  841.  
  842.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  843.                                              spriteTargetType, spriteTarget ) );
  844.     if ( actionAtom )
  845.         *actionAtom = theActionAtom;
  846.                                              
  847. bail:
  848.     return err;
  849. }
  850.  
  851. OSErr AddSpriteSetLayerAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  852.                                void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  853.                                short layer )
  854. {
  855.     OSErr    err = noErr;
  856.     QTAtom    actionAtom;
  857.     
  858.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteSetLayer, &actionAtom ) );
  859.  
  860.     layer = EndianS16_NtoB(layer);
  861.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(layer), &layer, nil ) );
  862.  
  863.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  864.                                              spriteTargetType, spriteTarget ) );
  865.  
  866. bail:
  867.     return err;
  868. }
  869.  
  870. OSErr AddSpriteSetGraphicsModeAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  871.                                       void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  872.                                       ModifierTrackGraphicsModeRecord *graphicsMode, QTAtom *actionAtom )
  873. {
  874.     OSErr                                err = noErr;
  875.     QTAtom                                theActionAtom;
  876.     ModifierTrackGraphicsModeRecord        bigEndianGraphicsMode;
  877.     
  878.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteSetGraphicsMode, &theActionAtom ) );
  879.  
  880.     bigEndianGraphicsMode                 = *graphicsMode;
  881.     bigEndianGraphicsMode.graphicsMode    = EndianU32_NtoB(bigEndianGraphicsMode.graphicsMode);
  882.     bigEndianGraphicsMode.opColor.red     = EndianU16_NtoB(bigEndianGraphicsMode.opColor.red);
  883.     bigEndianGraphicsMode.opColor.green    = EndianU16_NtoB(bigEndianGraphicsMode.opColor.green);
  884.     bigEndianGraphicsMode.opColor.blue    = EndianU16_NtoB(bigEndianGraphicsMode.opColor.blue);
  885.     
  886.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(ModifierTrackGraphicsModeRecord), 
  887.                                        &bigEndianGraphicsMode, nil ) );
  888.  
  889.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  890.                                              spriteTargetType, spriteTarget ) );
  891.  
  892.     if ( actionAtom )
  893.         *actionAtom = theActionAtom;
  894. bail:
  895.     return err;
  896. }
  897.  
  898. OSErr AddSpriteTranslateAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  899.                                       void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  900.                                       Fixed x, Fixed y, Boolean isRelative, QTAtom *actionAtom )
  901. {
  902.     OSErr    err = noErr;
  903.     QTAtom    theActionAtom;
  904.     
  905.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteTranslate, &theActionAtom ) );
  906.  
  907.     x = EndianS32_NtoB(x);
  908.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(x), &x, nil ) );
  909.  
  910.     y = EndianS32_NtoB(y);
  911.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSecondParam, sizeof(y), &y, nil ) );
  912.  
  913.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kThirdParam, sizeof(isRelative), &isRelative, nil ) );
  914.  
  915.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  916.                                              spriteTargetType, spriteTarget ) );
  917.  
  918.     if ( actionAtom )
  919.         *actionAtom = theActionAtom;
  920. bail:
  921.     return err;
  922. }
  923.  
  924. // •••• aboutX and aboutY are no longer parameters!!! Uses registration point now. Also, isRelative is gone.
  925. OSErr AddSpriteScaleAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  926.                             void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  927.                             Fixed xScale, Fixed yScale, Fixed aboutX, Fixed aboutY, Boolean isRelative, QTAtom *actionAtom )
  928. {
  929.     OSErr    err = noErr;
  930.     QTAtom    theActionAtom;
  931.     
  932.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteScale, &theActionAtom ) );
  933.  
  934.     xScale = EndianS32_NtoB(xScale);
  935.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(xScale), &xScale, nil ) );
  936.  
  937.     yScale = EndianS32_NtoB(yScale);
  938.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSecondParam, sizeof(yScale), &yScale, nil ) );
  939.  
  940.     aboutX = EndianS32_NtoB(aboutX);
  941.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kThirdParam, sizeof(aboutX), &aboutX, nil ) );
  942.  
  943.     aboutY = EndianS32_NtoB(aboutY);
  944.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFourthParam, sizeof(aboutY), &aboutY, nil ) );
  945.  
  946.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFifthParam, sizeof(isRelative), &isRelative, nil ) );
  947.  
  948.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  949.                                              spriteTargetType, spriteTarget ) );
  950.  
  951.     if ( actionAtom )
  952.         *actionAtom = theActionAtom;
  953. bail:
  954.     return err;
  955. }
  956.  
  957.  
  958. // •••• aboutX and aboutY are no longer parameters!!! Uses registration point now. Also, isRelative is gone.
  959.  
  960. OSErr AddSpriteRotateAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  961.                             void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  962.                             Fixed degrees, Fixed aboutX, Fixed aboutY, Boolean isRelative, QTAtom *actionAtom )
  963. {
  964.     OSErr    err = noErr;
  965.     QTAtom    theActionAtom;
  966.     
  967.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteRotate, &theActionAtom ) );
  968.  
  969.     degrees = EndianS32_NtoB(degrees);
  970.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(degrees), °rees, nil ) );
  971.  
  972.     aboutX = EndianS32_NtoB(aboutX);
  973.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSecondParam, sizeof(aboutX), &aboutX, nil ) );
  974.  
  975.     aboutY = EndianS32_NtoB(aboutY);
  976.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kThirdParam, sizeof(aboutY), &aboutY, nil ) );
  977.  
  978.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFourthParam, sizeof(isRelative), &isRelative, nil ) );
  979.  
  980.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  981.                                              spriteTargetType, spriteTarget ) );
  982.  
  983.     if ( actionAtom )
  984.         *actionAtom = theActionAtom;
  985. bail:
  986.     return err;
  987. }
  988.  
  989. // •••• isRelative is gone?
  990.  
  991. OSErr AddSpriteStretchAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  992.                             void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget, 
  993.                             Fixed p1x, Fixed p1y, Fixed p2x, Fixed p2y, Fixed p3x, Fixed p3y, Fixed p4x, Fixed p4y, 
  994.                             Boolean isRelative, QTAtom *actionAtom )
  995. {
  996.     OSErr    err = noErr;
  997.     QTAtom    theActionAtom;
  998.     
  999.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteStretch, &theActionAtom ) );
  1000.  
  1001.     p1x = EndianS32_NtoB(p1x);
  1002.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFirstParam, sizeof(p1x), &p1x, nil ) );
  1003.  
  1004.     p1y = EndianS32_NtoB(p1y);
  1005.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSecondParam, sizeof(p1y), &p1y, nil ) );
  1006.  
  1007.     p2x = EndianS32_NtoB(p2x);
  1008.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kThirdParam, sizeof(p2x), &p2x, nil ) );
  1009.  
  1010.     p2y = EndianS32_NtoB(p2y);
  1011.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFourthParam, sizeof(p2y), &p2y, nil ) );
  1012.  
  1013.     p3x = EndianS32_NtoB(p3x);
  1014.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kFifthParam, sizeof(p3x), &p3x, nil ) );
  1015.  
  1016.     p3y = EndianS32_NtoB(p3y);
  1017.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSixthParam, sizeof(p3y), &p3y, nil ) );
  1018.  
  1019.     p4x = EndianS32_NtoB(p4x);
  1020.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kSeventhParam, sizeof(p4x), &p4x, nil ) );
  1021.  
  1022.     p4y = EndianS32_NtoB(p4y);
  1023.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kEighthParam, sizeof(p4y), &p4y, nil ) );
  1024.  
  1025.     FailOSErr( AddActionParameterAtom( container, theActionAtom, kNinthParam, sizeof(isRelative), &isRelative, nil ) );
  1026.  
  1027.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, theActionAtom, trackTargetType, trackTarget, trackTypeIndex, 
  1028.                                              spriteTargetType, spriteTarget ) );
  1029.  
  1030.     if ( actionAtom )
  1031.         *actionAtom = theActionAtom;
  1032. bail:
  1033.     return err;
  1034. }
  1035.  
  1036. OSErr AddMusicPlayNoteAction( QTAtomContainer container, QTAtom atom, long whichEvent, long trackTargetType, 
  1037.                               void *trackTarget, long trackTypeIndex, long sampleDescIndex, long partIndex,
  1038.                               long pitch, long velocity, long duration )
  1039. {
  1040.     OSErr    err = noErr;
  1041.     QTAtom    actionAtom;
  1042.     
  1043.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionMusicPlayNote, &actionAtom ) );
  1044.  
  1045.     sampleDescIndex = EndianS32_NtoB(sampleDescIndex);
  1046.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(sampleDescIndex), &sampleDescIndex, nil ) );
  1047.     
  1048.     partIndex = EndianS32_NtoB(partIndex);
  1049.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, sizeof(partIndex), &partIndex, nil ) );
  1050.     
  1051.     pitch = EndianS32_NtoB(pitch);
  1052.     FailOSErr( AddActionParameterAtom( container, actionAtom, kThirdParam, sizeof(pitch), &pitch, nil ) );
  1053.     
  1054.     velocity = EndianS32_NtoB(velocity);
  1055.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFourthParam, sizeof(velocity), &velocity, nil ) );
  1056.     
  1057.     duration = EndianS32_NtoB(duration);
  1058.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFifthParam, sizeof(duration), &duration, nil ) );
  1059.  
  1060.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  1061.  
  1062. bail:
  1063.     return err;
  1064. }
  1065.  
  1066. OSErr AddSpriteTrackSetVariableAction( QTAtomContainer container, QTAtom atom, long whichEvent, QTAtomID variableID, float value, 
  1067.                                        long trackTargetType, void *trackTarget, long trackTypeIndex )
  1068. {
  1069.     OSErr    err = noErr;
  1070.     QTAtom    actionAtom;
  1071.     
  1072.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSpriteTrackSetVariable, &actionAtom ) );
  1073.  
  1074.     variableID = EndianU32_NtoB(variableID);
  1075.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(variableID), &variableID, nil ) );
  1076.  
  1077. //    value = EndianU32_NtoB(value);                // just flipping the 4 bytes
  1078.     EndianUtils_Float_NtoB(&value);
  1079.     
  1080.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, sizeof(value), &value, nil ) );
  1081.  
  1082.     FailOSErr( AddTrackTargetAtom( container, actionAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  1083.  
  1084. bail:
  1085.     return err;
  1086. }                                       
  1087.                         
  1088. OSErr AddGoToURLAction( QTAtomContainer container, QTAtom atom, long whichEvent, Handle urlLink )
  1089. {
  1090.     OSErr    err = noErr;
  1091.     QTAtom    actionAtom;
  1092.     
  1093.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionGoToURL, &actionAtom ) );
  1094.  
  1095.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, GetHandleSize(urlLink), *urlLink, nil ) );
  1096.  
  1097.     // no target for system actions
  1098.  
  1099. bail:
  1100.     return err;
  1101. }
  1102.  
  1103. OSErr AddSendQTEventAction( QTAtomContainer container, QTAtom atom, long whichEvent, QTEventRecordPtr theEvent,
  1104.                             long trackTargetType, void *trackTarget, long trackTypeIndex, long spriteTargetType, void *spriteTarget )
  1105. {
  1106.     OSErr    err = noErr;
  1107.     QTAtom    actionAtom, paramAtom;
  1108.     
  1109.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionSendQTEventToSprite, &actionAtom ) );
  1110.  
  1111.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, 0, nil, ¶mAtom ) );
  1112.  
  1113.     // note that these target atoms are the first parameter to the kActionSendQTEvent action 
  1114.     FailOSErr( AddTrackAndSpriteTargetAtoms( container, paramAtom, trackTargetType, trackTarget, trackTypeIndex, 
  1115.                                              spriteTargetType, spriteTarget ) );
  1116.  
  1117.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, sizeof(*theEvent), theEvent, ¶mAtom ) );
  1118.  
  1119. bail:
  1120.     return err;
  1121. }                                       
  1122.                         
  1123. OSErr AddDebugStrAction( QTAtomContainer container, QTAtom atom, long whichEvent, Str255 theString )
  1124. {
  1125.     OSErr    err = noErr;
  1126.     QTAtom    actionAtom;
  1127.     
  1128.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionDebugStr, &actionAtom ) );
  1129.  
  1130.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, theString[0] + 1, theString, nil ) );
  1131.  
  1132.     // no target for system actions
  1133.  
  1134. bail:
  1135.     return err;
  1136. }
  1137.  
  1138. OSErr AddPushCurrentTimeAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  1139. {
  1140.     OSErr    err = noErr;
  1141.     QTAtom    actionAtom;
  1142.     
  1143.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionPushCurrentTime, &actionAtom ) );
  1144.  
  1145.     // no target for system actions
  1146.  
  1147. bail:
  1148.     return err;
  1149. }
  1150.             
  1151. OSErr AddPushCurrentTimeWithLabelAction( QTAtomContainer container, QTAtom atom, long whichEvent, Str255 theLabel )
  1152. {
  1153.     OSErr    err = noErr;
  1154.     QTAtom    actionAtom;
  1155.     
  1156.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionPushCurrentTimeWithLabel, &actionAtom ) );
  1157.  
  1158.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, theLabel[0] + 1, theLabel, nil ) );
  1159.  
  1160.     // no target for system actions
  1161.  
  1162. bail:
  1163.     return err;
  1164. }
  1165.         
  1166.         
  1167. OSErr AddPopAndGotoTopTimeAction( QTAtomContainer container, QTAtom atom, long whichEvent )
  1168. {
  1169.     OSErr    err = noErr;
  1170.     QTAtom    actionAtom;
  1171.     
  1172.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionPopAndGotoTopTime, &actionAtom ) );
  1173.  
  1174.     // no target for system actions
  1175.  
  1176. bail:
  1177.     return err;
  1178. }
  1179.  
  1180. OSErr AddPopAndGotoLabeledTimeAction( QTAtomContainer container, QTAtom atom, long whichEvent, Str255 theLabel )
  1181. {
  1182.     OSErr    err = noErr;
  1183.     QTAtom    actionAtom;
  1184.     
  1185.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionPopAndGotoLabeledTime, &actionAtom ) );
  1186.  
  1187.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, theLabel[0] + 1, theLabel, nil ) );
  1188.  
  1189.     // no target for system actions
  1190.  
  1191. bail:
  1192.     return err;
  1193. }
  1194.  
  1195. OSErr AddApplicationNumberAndStringAction( QTAtomContainer container, QTAtom atom, long whichEvent, long theNumber, Str255 theString )
  1196. {
  1197.     OSErr    err = noErr;
  1198.     QTAtom    actionAtom;
  1199.     
  1200.     FailOSErr( AddQTEventAndActionAtoms( container, atom, whichEvent, kActionApplicationNumberAndString, &actionAtom ) );
  1201.  
  1202.     theNumber = EndianS32_NtoB(theNumber);
  1203.     FailOSErr( AddActionParameterAtom( container, actionAtom, kFirstParam, sizeof(theNumber), &theNumber, nil ) );
  1204.  
  1205.     FailOSErr( AddActionParameterAtom( container, actionAtom, kSecondParam, theString[0] + 1, theString, nil ) );
  1206.  
  1207.     // no target for system actions
  1208.  
  1209. bail:
  1210.     return err;
  1211. }
  1212.                         
  1213.                                
  1214. // ________ Interpreted Actions __________
  1215.  
  1216. OSErr AddOperandAtom( QTAtomContainer container, QTAtom operatorAtom, QTAtomType operandType, short operandIndex,
  1217.                       QTAtomContainer operandAtoms, float constantValue )
  1218. {
  1219.     OSErr     err = noErr;
  1220.     QTAtom    operandAtom, operandTypeAtom;
  1221.     
  1222.     FailOSErr( QTInsertChild( container, operatorAtom, kOperandAtomType, 0, operandIndex, 0, nil, &operandAtom ) );
  1223.     
  1224.     FailOSErr( QTInsertChild( container, operandAtom, operandType, 1, 1, 0, nil, &operandTypeAtom ) );
  1225.  
  1226.     if ( operandType == kOperandConstant ) {
  1227.     
  1228.         EndianUtils_Float_NtoB(&constantValue);
  1229.     //    constantValue = EndianU32_NtoB(constantValue);
  1230.         FailOSErr( QTSetAtomData( container, operandTypeAtom, sizeof( constantValue ), &constantValue ) );
  1231.     }
  1232.     else {
  1233.         FailOSErr( QTInsertChildren( container, operandTypeAtom, operandAtoms ) );
  1234.     }
  1235.     
  1236. bail:
  1237.     return err;
  1238. }
  1239.  
  1240. OSErr AddVariableOperandAtom( QTAtomContainer container, QTAtom operatorAtom, short operandIndex,
  1241.                                 long trackTargetType, void *trackTarget, long trackTypeIndex, QTAtomID variableID )
  1242. {
  1243.     OSErr     err = noErr;
  1244.     QTAtom    operandAtom, operandTypeAtom;
  1245.     
  1246.     FailOSErr( QTInsertChild( container, operatorAtom, kOperandAtomType, 0, operandIndex, 0, nil, &operandAtom ) );
  1247.     
  1248.     FailOSErr( QTInsertChild( container, operandAtom, kOperandSpriteTrackVariable, 1, 1, 0, nil, &operandTypeAtom ) );
  1249.  
  1250.     variableID = EndianU32_NtoB(variableID);
  1251.     FailOSErr( QTInsertChild( container, operandTypeAtom, kActionParameter, 1, 1, sizeof(variableID), &variableID, nil ) );
  1252.  
  1253.     FailOSErr( AddTrackTargetAtom( container, operandTypeAtom, trackTargetType, trackTarget, trackTypeIndex ) );
  1254.         
  1255. bail:
  1256.     return err;
  1257. }
  1258.  
  1259. OSErr AddOperatorAtom( QTAtomContainer container, QTAtom expressionAtom, QTAtomID theOperatorType, QTAtom *operatorAtom )
  1260. {
  1261.     return QTInsertChild( container, expressionAtom, kOperatorAtomType, theOperatorType, 1, 0, nil, operatorAtom );
  1262. }
  1263.  
  1264. OSErr AddExpressionContainerAtomType( QTAtomContainer container, QTAtom atom, QTAtom *expressionAtom )
  1265. {
  1266.     return QTInsertChild( container, atom, kExpressionContainerAtomType, 1, 1, 0, nil, expressionAtom );
  1267. }
  1268.  
  1269. OSErr AddConditionalAtom( QTAtomContainer container, QTAtom atom, short conditionIndex, QTAtom *conditionalAtom )
  1270. {
  1271.     return QTInsertChild( container, atom, kConditionalAtomType, 0, conditionIndex, 0, nil, conditionalAtom );
  1272. }
  1273.  
  1274. OSErr AddActionListAtom( QTAtomContainer container, QTAtom atom, QTAtom *actionListAtom )
  1275. {
  1276.     return QTInsertChild( container, atom, kActionListAtomType, 1, 1, 0, nil, actionListAtom );
  1277. }
  1278.  
  1279.